#pragma once

#include "fxcc/core/graph/opengl3/IndexBuffer.h"
#include "fxcc/core/graph/opengl3/VertexBuffer.h"
#include "fxcc/core/graph/opengl3/VertexArray.h"

#include "fxcc/core/graph/common/MeshJack.h"


namespace fxcc
{
    namespace graph
    {
        namespace opengl3
        {
            struct FXCC_API  MeshJack :public fxcc::graph::common::MeshJack, public fxcc::graph::opengl3::VertexArray
            {
                fxcc::graph::opengl3::IndexBuffer m_IndexBuffer;

                std::vector<fxcc::graph::opengl3::VertexBuffer> m_VertexBuffers;

                template <typename T>
                void SetVertexBufferIndexFloat(const int index, bool normalized)
                {
                    VertexArray::EnablePointer(index);
                    VertexArray::ArrtibPointer(index, sizeof(T) / sizeof(float), GL_FLOAT, normalized, sizeof(T), 0);
                };

                template <typename T>
                void SetVertexBufferIndexInteger(const int index, bool isSigned = true)
                {
                    VertexArray::EnablePointer(index);
                    VertexArray::AttribIPointer(index, sizeof(T) / sizeof(int), isSigned ? GL_INT : GL_UNSIGNED_INT, sizeof(T), 0);
                };

                void LoadMSDFBuffersFrom(const fxcc::graph::common::MSDFGeoData& geoData);

                void LoadSDFBuffersFrom(const fxcc::graph::common::SDFGeoData& geoData);

                void LoadFixedMeshBuffersFrom(const fxcc::graph::common::GeometryData& geoData);

                void LoadSkinnedMeshBuffers(const fxcc::graph::common::GeometryData& geoData, const fxcc::graph::common::SkinnedMeshData& skinnedMeshData);

                MeshJack(const fxcc::graph::common::MSDFGeoData& geoData);
                
                MeshJack(const fxcc::graph::common::GeometryData& geoData);

                MeshJack(const fxcc::graph::common::GeometryData& geoData, const fxcc::graph::common::SkinnedMeshData& skinnedMeshData);

                void OnEndCreate();

                void Bind() const override
                {
                    VertexArray::Bind();
                }

                void DrawElementsAuto() const override;

            };
        }
    }
};
